<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="矿井名称" prop="mineName">
        <el-input
          v-model="queryParams.mineName"
          placeholder="请输入矿井名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['dispatch:information:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['dispatch:information:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['dispatch:information:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['dispatch:information:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="informationList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="mineInfoId" />
<!--
      <el-table-column label="排序" align="center" prop="orderNumber" />
-->
      <el-table-column label="矿井名称" align="center" prop="mineName" />
<!--      <el-table-column label="矿井 ID" align="center" prop="deptId" />
      <el-table-column label="矿井名称" align="center" prop="deptName" />-->
      <el-table-column label="资源储量" align="center" prop="reserves" />
      <el-table-column label="核定生产能力" align="center" prop="throughput" />
      <el-table-column label="设计服务年限" align="center" prop="workYear" />
      <el-table-column label="正常涌水量" align="center" prop="waterInflow" />
      <el-table-column label="瓦斯等级" align="center" prop="gasGrade" />
      <el-table-column label="自然发火期" align="center" prop="sctp" />
      <el-table-column label="水文地质类型" align="center" prop="hydrogeololgyType" />
      <el-table-column label="最大涌水量" align="center" prop="maxWaterInflow" />
      <el-table-column label="区划" align="center" prop="compartment" />
      <el-table-column label="煤田/井田" align="center" prop="coalfield" />
      <el-table-column label="开拓方式" align="center" prop="developmentForm" />
      <el-table-column label="煤尘爆炸指数" align="center" prop="explosionIndex" />
      <el-table-column label="核定采掘头面数" align="center" prop="diggingNumber" />
      <el-table-column label="单位类型" align="center" prop="deptType" />
      <el-table-column label="是否关闭" align="center" prop="isClosed" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.isClosed"/>
        </template>
      </el-table-column>
      <el-table-column label="关闭时间" align="center" prop="closedDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.closedDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建者" align="center" prop="createBy" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['dispatch:information:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['dispatch:information:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改矿井基础信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="排序" prop="orderNumber">
          <el-input v-model="form.orderNumber" placeholder="请输入排序" />
        </el-form-item>
        <el-form-item label="矿井名称" prop="mineName">
          <el-input v-model="form.mineName" placeholder="请输入矿井名称" />
        </el-form-item>
        <el-form-item label="资源储量" prop="reserves">
          <el-input v-model="form.reserves" placeholder="请输入资源储量" />
        </el-form-item>
        <el-form-item label="核定生产能力" prop="throughput">
          <el-input v-model="form.throughput" placeholder="请输入核定生产能力" />
        </el-form-item>
        <el-form-item label="设计服务年限" prop="workYear">
          <el-input v-model="form.workYear" placeholder="请输入设计服务年限" />
        </el-form-item>
        <el-form-item label="正常涌水量" prop="waterInflow">
          <el-input v-model="form.waterInflow" placeholder="请输入正常涌水量" />
        </el-form-item>
        <el-form-item label="水文地质类型" prop="hydrogeololgyType" clearable>
          <el-select v-model="form.hydrogeololgyType" placeholder="请选择水文地质类型" clearable>
            <el-option label="简单" value="简单"></el-option>
            <el-option label="中等" value="中等"></el-option>
            <el-option label="复杂" value="复杂"></el-option>
            <el-option label="极复杂" value="极复杂"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="瓦斯等级" prop="gasGrade">
          <el-select v-model="form.gasGrade" placeholder="请选择瓦斯等级" clearable>
            <el-option label="低瓦斯矿井" value="低瓦斯矿井"></el-option>
            <el-option label="高瓦斯矿井" value="高瓦斯矿井"></el-option>
            <el-option label="煤与瓦斯突出矿井" value="煤与瓦斯突出矿井"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="自然发火期" prop="sctp">
          <el-input v-model="form.sctp" placeholder="请输入自然发火期" />
        </el-form-item>
        <el-form-item label="最大涌水量" prop="maxWaterInflow">
          <el-input v-model="form.maxWaterInflow" placeholder="请输入最大涌水量" />
        </el-form-item>
        <el-form-item label="区划" prop="compartment">
          <el-input v-model="form.compartment" placeholder="请输入区划" />
        </el-form-item>
        <el-form-item label="煤田/井田" prop="coalfield">
          <el-input v-model="form.coalfield" placeholder="请输入煤田/井田" />
        </el-form-item>
        <el-form-item label="开拓方式" prop="developmentForm">
          <el-select v-model="form.developmentForm" placeholder="请选择开拓方式" clearable>
            <el-option label="立井开拓" value="立井开拓"></el-option>
            <el-option label="斜井开拓" value="斜井开拓"></el-option>
            <el-option label="平硐开拓" value="平硐开拓"></el-option>
            <el-option label="综合开拓" value="综合开拓"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="煤尘爆炸指数" prop="explosionIndex">
          <el-select v-model="form.explosionIndex" placeholder="请选择煤尘爆炸指数" clearable>
            <el-option label="小于10%不爆炸" value="小于10%不爆炸"></el-option>
            <el-option label="10%～15%爆炸性较弱" value="10%～15%爆炸性较弱"></el-option>
            <el-option label="15%～28%爆炸性较强" value="15%～28%爆炸性较强"></el-option>
            <el-option label="大于28%爆炸性强烈" value="大于28%爆炸性强烈"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="核定采掘头面数" prop="diggingNumber">
          <el-input v-model="form.diggingNumber" placeholder="请输入核定采掘头面数" />
        </el-form-item>
        <el-form-item label="单位类型" prop="deptType">
          <el-select v-model="form.deptType" placeholder="请选择单位类型" clearable>
            <el-option label="煤矿" value="煤矿"></el-option>
            <el-option label="铁矿" value="铁矿"></el-option>
            <el-option label="玻纤" value="玻纤"></el-option>
            <el-option label="二级公司" value="二级公司"></el-option>
            <el-option label="其他" value="其他"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否关闭" prop="isClosed">
          <el-select v-model="form.isClosed" placeholder="请选择是否关闭" clearable>
            <el-option
              v-for="dict in dict.type.sys_yes_no"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="关闭时间" prop="closedDate">
          <el-date-picker clearable
            v-model="form.closedDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择关闭时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listInformation, getInformation, delInformation, addInformation, updateInformation } from "@/api/dispatch/information";

export default {
  name: "Information",
  dicts: ['sys_yes_no'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 矿井基础信息表格数据
      informationList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        mineName: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询矿井基础信息列表 */
    getList() {
      this.loading = true;
      listInformation(this.queryParams).then(response => {
        this.informationList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        mineInfoId: null,
        orderNumber: null,
        mineName: null,
        deptId: null,
        deptName: null,
        reserves: null,
        throughput: null,
        workYear: null,
        waterInflow: null,
        gasGrade: null,
        sctp: null,
        hydrogeololgyType: null,
        attachmentPath: null,
        isDel: null,
        maxWaterInflow: null,
        compartment: null,
        coalfield: null,
        developmentForm: null,
        explosionIndex: null,
        diggingNumber: null,
        deptType: null,
        isDataLocked: null,
        isClosed: null,
        closedDate: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.mineInfoId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加矿井基础信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const mineInfoId = row.mineInfoId || this.ids
      getInformation(mineInfoId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改矿井基础信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.mineInfoId != null) {
            updateInformation(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInformation(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const mineInfoIds = row.mineInfoId || this.ids;
      this.$modal.confirm('是否确认删除矿井基础信息编号为"' + mineInfoIds + '"的数据项？').then(function() {
        return delInformation(mineInfoIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('dispatch/information/export', {
        ...this.queryParams
      }, `information_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
